// This example shows how to read a value from a single node that is an array of UInt16. // // Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . using System; using OpcLabs.EasyOpc.UA; using OpcLabs.EasyOpc.UA.OperationModel; namespace UADocExamples._EasyUAClient { partial class ReadValue { public static void ArrayOfUInt16() { UAEndpointDescriptor endpointDescriptor = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"; // or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported) // or "https://opcua.demo-this.com:51212/UA/SampleServer/" // Instantiate the client object var client = new EasyUAClient(); Console.WriteLine("Obtaining value of a node..."); int[] value; try { // UInt16 is returned as Int32, because UInt16 is not a CLS-compliant type (and is not supported in VB.NET). value = (int[])client.ReadValue(endpointDescriptor, "nsu=http://test.org/UA/Data/ ;ns=2;i=10932"); // /Data.Dynamic.Array.UInt16Value } catch (UAException uaException) { Console.WriteLine($"*** Failure: {uaException.GetBaseException().Message}"); return; } if (!(value is null)) { Console.WriteLine(value[0]); Console.WriteLine(value[1]); Console.WriteLine(value[2]); } Console.WriteLine("Finished."); } } }
# This example shows how to read a value from a single node that is an array of UInt16. # # Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . # OPC client and subscriber examples in Python on GitHub: https://github.com/OPCLabs/Examples-QuickOPC-Python . # The QuickOPC package is needed. Install it using "pip install opclabs_quickopc". import opclabs_quickopc # Import .NET namespaces. from OpcLabs.EasyOpc.UA import * from OpcLabs.EasyOpc.UA.OperationModel import * # Instantiate the client object. client = EasyUAClient() print('Obtaining value of a node...') try: # UInt16 is returned as Int32, because UInt16 is not a CLS-compliant type (and is not supported in VB.NET). value = IEasyUAClientExtension.ReadValue(client, UAEndpointDescriptor('opc.tcp://opcua.demo-this.com:51210/UA/SampleServer'), UANodeDescriptor('nsu=http://test.org/UA/Data/ ;ns=2;i=10932')) # /Data.Dynamic.Array.UInt16Value except UAException as uaException: print('*** Failure: ' + uaException.GetBaseException().Message) exit() # Display results. if value is not None: print(value[0]) print(value[1]) print(value[2]) print() print('Finished.')
' This example shows how to read a value from a single node that is an array of UInt16. ' ' Find all latest examples here: https://opclabs.doc-that.com/files/onlinedocs/OPCLabs-OpcStudio/Latest/examples.html . Imports OpcLabs.EasyOpc.UA Imports OpcLabs.EasyOpc.UA.OperationModel Namespace _EasyUAClient Partial Friend Class ReadValue Public Shared Sub ArrayOfUInt16() ' Define which server we will work with. Dim endpointDescriptor As UAEndpointDescriptor = "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer" ' or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported) ' or "https://opcua.demo-this.com:51212/UA/SampleServer/" ' Instantiate the client object Dim client = New EasyUAClient() Console.WriteLine("Obtaining value of a node...") Dim value As Int32() Try ' UInt16 is returned as Int32, because UInt16 is not a CLS-compliant type (and is not supported in VB.NET). ' // /Data.Dynamic.Array.UInt16Value value = CType(client.ReadValue(endpointDescriptor, "nsu=http://test.org/UA/Data/ ;ns=2;i=10932"), Int32()) Catch uaException As UAException Console.WriteLine("*** Failure: {0}", uaException.GetBaseException.Message) Exit Sub End Try If Not IsNothing(value) Then Console.WriteLine(value(0)) Console.WriteLine(value(1)) Console.WriteLine(value(2)) End If End Sub End Class End Namespace
Copyright © 2004-2024 CODE Consulting and Development, s.r.o., Plzen. All rights reserved. Web page: www.opclabs.com
Send Documentation Feedback. Resources: Knowledge Base, Product Downloads. Technical support: Online Forums, FAQ.Missing some example? Ask us for it on our Online Forums! You do not have to own a commercial license in order to use Online Forums, and we reply to every post.